// Quantitative Angiogram Analysis System
//
// Copyright ?Ping Zou, 2006
// sg71.cherub@gmail.com

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using WeifenLuo.WinFormsUI;
using System.IO;
using System.Xml;

namespace eee.Sheffield.PZ.QAAS
{ 
    /// <summary>
    /// log form
    /// </summary>
    public partial class LogForm : DockContent
    {
        private static string logFile = Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), "QAASLogFil.xml");     
        
        public LogForm()
        {
            InitializeComponent();
        }

        /// <summary>
        /// Save
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void saveLogToolStripButton_Click(object sender, EventArgs e)
        {
            Save(logFile);
        }
        /// <summary>
        /// Save method
        /// </summary>
        /// <param name="fileName"></param>
        public void Save(string fileName)
        {
            // open file
            FileStream fs = new FileStream(fileName, FileMode.Create);
            // create XML writer
            XmlTextWriter xmlOut = new XmlTextWriter(fs, Encoding.Unicode);

            // use indenting for readability
            xmlOut.Formatting = Formatting.Indented;

            // start document
            xmlOut.WriteStartDocument();
            xmlOut.WriteComment("QAAS log file");

            // main node
            xmlOut.WriteStartElement("QAASLog");

            // log node
            string logText = txtLog.Text;
            string[] logLines = logText.Split('\r');
            foreach (string log in logLines)
            {
                xmlOut.WriteStartElement("Log");
                xmlOut.WriteString(log);
                xmlOut.WriteEndElement();
            }

            xmlOut.WriteEndElement();
            xmlOut.WriteEndDocument();
            // close file
            xmlOut.Close();
        }
    }
}